package com.sumainfor.pc.epc.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.epc.feign.Zfeign.ZzuulFeign;
import com.sumainfor.pc.epc.service.MaintenanceWorkbenchService;
import com.sumainfor.pc.epc.service.RepairEvaService;
import com.sumainfor.pc.epc.service.impl.RepairEvaServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 维修师傅（工作台）
 * <p>
 *
 * @author: zhoucong1
 * @create: 2019-04-09 12:00
 **/
@Controller
@RequestMapping("/maintenanceWorkbench")
public class MaintenanceWorkbenchController {

    @Autowired
    MaintenanceWorkbenchService maintenanceWorkbenchService;

    @Autowired
    ZzuulFeign zzuulFeign;


    /**
    * <p>
    * 重要状态提醒
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @GetMapping("/importantState")
    public JsonResult importantState(){
        return maintenanceWorkbenchService.importantState();
    }


    /**
    * <p>
    * 系统消息提醒
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @GetMapping("/systemMessage")
    public JsonResult systemMessage(@RequestParam Map<String,Object> params, Pager pager){
        System.out.println("asd"+params);
        JsonResult result = new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params ,new String[]{"MeType"})){
            return  result.putFailed("消息角色不能为空...");
        }
        return zzuulFeign.getMessageList(params,pager);


    }



    /**
     * <p>
     * 维修工单池
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @ResponseBody
    @GetMapping("/getRepairList")
    public JsonResult getRepairList(@RequestParam Map<String,Object> params ,Pager pager){
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = maintenanceWorkbenchService.getRepairCount();
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,0);
        }
        List<Map<String,Object>> getRepairList = maintenanceWorkbenchService.getRepairList(params);

        return pageUtils.getJsonResult(getRepairList, params, cout);

    }

    /**
     * 查询维修评价 已评价
     * @Author zhoucong
     * @Description //TODO
     * @Date 2018/11/3 21:22
     */
    @ResponseBody
    @RequestMapping(value = "/getRepairEvaList",method = RequestMethod.GET)
    public JsonResult getRepairEvaList(@RequestParam Map<String,Object>params, Pager pager){
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = maintenanceWorkbenchService.getRepairEvaCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,0);
        }
        List<Map<String,Object>> getRepairEvaList = maintenanceWorkbenchService.getRepairEvaList(params);

        return pageUtils.getJsonResult(getRepairEvaList, params, cout);
    }




    }


